package com.gin.web.dto;


import com.gin.web.exp.ExpCode;

/**
 * 返回的dto 类
 */
public class ResultMsg<T> {

    private boolean success;
    private int code;
    private String msg;
    private T data;

    public boolean isSuccess() {
        return success;
    }

    public ResultMsg setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public int getCode() {
        return code;
    }

    public ResultMsg setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public ResultMsg setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public ResultMsg setData(T data) {
        this.data = data;
        return this;
    }

    /**
     * 构件错误信息
     *
     * @param serviceCode
     * @return
     */
    public ResultMsg buildError(ExpCode serviceCode) {
        this.setSuccess(false).setCode(serviceCode.code);
        this.setMsg(serviceCode.msg);
        return this;
    }

    /**
     * 构建正确的数据返回对象
     *
     * @param data 数据
     * @return
     */
    public ResultMsg<T> buildSuccessData(T data) {
        this.setCode(ExpCode.SUCCESS_CODE.code).setSuccess(true);
        this.setData(data).setMsg(ExpCode.SUCCESS_CODE.msg);
        return this;
    }
}
